[C#, Regex] EOL Special Char not matching
Posted
by Aurélien Ribon
on Stack Overflow
See other posts from Stack Overflow
or by Aurélien Ribon
Published on 2010-03-19T20:55:56Z
Indexed on
2010/03/19
21:01 UTC
Read the original article
Hit count: 359
Hello,
I am trying to find every "a -> b, c, d" pattern in an input string. The pattern I am using is the following :
"^[ \t]*(\\w+)[ \t]*->[ \t]*(\\w+)(,[ \t]*\\w+)*$"
The input is :
a -> b
b -> c
c -> d
The function is :
private void ParseAndBuildGraph(String input) {
MatchCollection mc = Regex.Matches(input, "^[ \t]*(\\w+)[ \t]*->[ \t]*(\\w+)(,[ \t]*\\w+)*$", RegexOptions.Multiline);
foreach (Match m in mc) {
Debug.WriteLine(m.Value);
}
}
The output is :
c -> d
Actually, there is a problem with the line ending "$" special char. If I insert a "\r" before "$", it works, but I thought "$" would match any line termination (with the Multiline option), especially a \r\n in a Windows environment. Is it not the case ?
© Stack Overflow or respective owner